package com.androider.timememory.activity;

import java.util.ArrayList;
import java.util.HashMap;

import com.androider.timememory.R;
import com.androider.timememory.db.RecordModel;
import com.androider.timememory.utils.ActivityUtil;
import com.androider.timememory.utils.Constants;
import com.androider.timememory.utils.DeviceUtil;
import com.androider.timememory.view.PageView;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Album extends Activity {

	private static final String TAG = "Album";
	public static final String ALBUM_DATA_TYPE = "AlbumDataType";
	public static final String ALBUM_DATA_TYPE_SEARCH = "AlbumDataTypeSearch";
	public static final String ALBUM_SEARCH_STR = "AlbumSearchStr";
	private PageView pageView;
	private int width;
	private int height;
	private String dataType;
	private String searchStr;
	private Bitmap bgBitmap;
	ArrayList<HashMap<String, Object>> data;

	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        dataType = this.getIntent().getStringExtra(Album.ALBUM_DATA_TYPE);
        if(dataType != null && dataType.equals(ALBUM_DATA_TYPE_SEARCH)){
        	searchStr = this.getIntent().getStringExtra(Album.ALBUM_SEARCH_STR);
        	if(searchStr != null){
        		data = RecordModel.searchByNote(this, searchStr);
            	bgBitmap = BitmapFactory.decodeResource(this.getResources(),
    					R.drawable.album_bg_03);
        	}
        }else{
        	data = RecordModel.getRecordListByCategory(this, dataType);
    		if(dataType.equals(Constants.DATA_TYPE_FAMILY)) {
    			bgBitmap = BitmapFactory.decodeResource(this.getResources(),
    					R.drawable.album_bg_01);
            } else if(dataType.equals(Constants.DATA_TYPE_LOVER)) {
            	bgBitmap = BitmapFactory.decodeResource(this.getResources(),
    					R.drawable.album_bg_02);
            } else if(dataType.equals(Constants.DATA_TYPE_FRIEND)) {
            	bgBitmap = BitmapFactory.decodeResource(this.getResources(),
    					R.drawable.album_bg_03);
            }
        }
        
        if(data == null || data.size() == 0){
        	if(dataType != null && dataType.equals(ALBUM_DATA_TYPE_SEARCH)){
            	Intent intent = new Intent(this, TimeMemory.class);
            	this.startActivity(intent);
            	ActivityUtil.showLongTip(this, R.string.sms_receive_list_null);
        	}
        	ActivityUtil.showLongTip(this, R.string.sms_receive_list_null2);
        	this.finish();
        	return;
        }
        
        width = DeviceUtil.getScreenWidth(this);
        height = DeviceUtil.getScreenHeight(this);
        pageView = new PageView(this, width, height, data, bgBitmap);
        setContentView(pageView);

    }

	/* (non-Javadoc)
	 * @see android.app.Activity#onDestroy()
	 */
	@Override
	protected void onDestroy() {
		if(bgBitmap != null){
			bgBitmap.recycle();
		}
		super.onDestroy();
	}

}